<template>
	<div class="">
		<Navbar></Navbar>
		<div class="text-center fs_large bold c-text">
			安能智保光伏运营期保障方案
		</div>
		<div class="p-4">
			<StageBar :active="0"></StageBar>
			<div class="mb-3">
				<vSubmitFile ref="form" :businessId="businessId">
					<div slot="footer" class="text-center">
						<el-button type="primary" @click="submit"
							>下一步，订单提交</el-button
						>
					</div>
				</vSubmitFile>
			</div>
			<div v-if="showOrderInfo">
				<vForm v-bind="defaultOrderData" readonly>
					<div slot="header">
						<span class="fs_large bold"
							>项目信息<span class="c9 fs_medium">（查看）</span></span
						>
					</div>
				</vForm>
			</div>
		</div>
	</div>
</template>

<script>
import StageBar from './components/StageBar.vue'
import { saveGfbForm, orderDetail } from './api/order'
import vSubmitFile from './components/submitFile.vue'
import vForm from './Input/vForm.vue'
import Navbar from '@/components/Navbar'
export default {
	props: {
		businessId: Number
	},
	data() {
		return {
			showOrderInfo: false,
			defaultOrderData: {}
		}
	},
	computed: {},
	mounted() {
		orderDetail({ businessId: this.businessId })
			.then((res) => {
				debugger
				const defaultQixian = {
					startTime: res.data.order.startTime,
					endTime: res.data.order.endTime
				}
				const defaultToubao = {
					customerName: res.data.order.holder.name,
					certNum: res.data.order.holder.idNum,
					phone: res.data.order.holder.phone,
					contactName: res.data.order.holder.contactName,
					businessLicense: res.data.order.holder.businessLicense,
					address: res.data.order.holder.detailAddress
				}

				const defaultRisks = res.data.order.risks
				const defaultBase = res.data.subjects[0]
				const defaultSameAs = res.data.order.holder.same

				var defaultBeibao = {}
				if (!defaultSameAs) {
					defaultBeibao = {
						customerName: res.data.order.relations[0].name,
						certNum: res.data.order.relations[0].idNum,
						contactPhone: res.data.order.relations[0].phone,
						contactName: res.data.order.relations[0].contactName,
						businessLicense: res.data.order.relations[0].businessLicense,
						address: res.data.order.relations[0].detailAddress
					}
				}

				this.defaultOrderData = {
					defaultQixian,
					defaultToubao,
					defaultBeibao,
					defaultRisks,
					defaultBase,
					defaultSameAs
				}

				this.showOrderInfo = true
			})
			.finally(() => {
				this.showOrderInfo = true
			})
	},
	methods: {
		submit() {
			this.$refs.form.validate().then((params) => {
				params.entity = { ...params.entity, ...this.bbInfo }

				this.loading = true
				saveGfbForm(params, { businessId: this.businessId })
					.then(() => {
						this.$message.success('保存成功')
						this.$router.push({
							path: '/11837/submit-success',
							query: {
								businessId: this.businessId
							}
						})
					})
					.finally(() => {
						this.loading = false
					})
			})
		}
	},
	components: {
		// XhForm,
		vForm,
		Navbar,
		vSubmitFile,
		StageBar
	}
}
</script>

<style lang="scss" scoped="scoped"></style>
